<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>우편번호 검색</title>
<style type="text/css">
<!--
body { margin: 0; font-size:12px; }
td { font-size:12px; }
a:link   { font-family:"돋움"; text-decoration:none; color:#000000; line-height: 18px;}
a:active  { font-family:"돋움"; text-decoration:none; color:#000000; line-height: 18px;}
a:visited  { font-family:"돋움"; text-decoration:none; color:#000000; line-height: 18px;}
a:hover  { font-family:"돋움"; text-decoration:underline;  color:#000000; line-height: 18px;}
-->
</style>
<script type="text/javascript">
function copy(address) {
	opener.<?php echo $_GET['form_name'].'.'.$_GET['addr_field_name'].'.value = '; ?>address;
	window.close();
}
</script>
</head>
<body onload="javascript:document.getElementById('s').focus();">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top" bgcolor="#eeeeee"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td style="letter-spacing:-1px; padding: 0 20px 17px 20px">검색을 원하시는 주소지를 동/읍/면 단위로 입력한 다음, <font color="#ED0063"><strong>검색 버튼</strong></font>을 누르세요.<br>
          (예 : 서초동 → 서초,  부안읍 → 부안,  수내면 → 수내 )</td>
      </tr>
      <tr>
        <td style="padding: 0 15px 0 20px;">
          <center>
						<form action="<? echo $_SERVER['PHP_SELF'] ?>?form_name=<?php echo $_GET['form_name']; ?>&addr_field_name=<?php echo $_GET['addr_field_name']; ?>" method="post">
							<strong>읍/면/동</strong>
							<input id="s" name="s" type="text" size="30" value="<?=$s?>">
							<input type="submit" name="submit" value="검색" align="absmiddle">
							<input type="hidden" id="form_name" name="form_name" value="<?php echo $_GET['form_name']; ?>" />
							<input type="hidden" id="addr_field_name" name="addr_field_name" value="<?php echo $_GET['addr_field_name']; ?>" />
						</form>
          </center>
					<?php
					require_once('db_connect.php'); 
					$s=$_POST['s'];
					if($s) {
						$query = "select * from postcode where (gugun like '%$s%') or (dong like '%$s%') ";
						$result = mysqli_query($conn, $query);
						while($data = mysqli_fetch_array($result))  {
							$zipcode = $data[zipcode];
							$sido = $data[sido];
							$gugn = $data[gugun];
							$dong		= $data[dong];
							$bunji = $data[bungi];
							
							$tmp = explode("-",$zipcode);
							$a = $tmp[0];
							$b = $tmp[1];
					?>
							<form name="addr" method="post">
										<a href="#" onclick="copy('<?=$sido?> <?=$gugn?> <?=$dong?> <?=$ri?>')">
										[<?=$a?>-<?=$b?>] <?=$sido?> <?=$gugn?> <?=$dong?> <?=$ri?> <?=$bunji?></a><br>
							</form>
					<?php
							}
						}
						else {
							echo "검색하지 않았거나, 검색결과가 없습니다.";
						}
					?>
        </td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>